<template>
  <div class="home">
    <div class="welcome-section">
      <div class="welcome-content">
        <h1>知识图谱管理系统</h1>
        <p class="subtitle">智能化知识管理与分析平台</p>
      </div>
    </div>
    
    <div class="content-section">
      <div class="features-grid">
        <el-card class="feature-card" @click="$router.push('/document')">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Document /></el-icon>
            </div>
            <div class="text-content">
              <h2>知识抽取</h2>
              <p>智能文档解析与知识提取，支持多种格式文档上传和处理</p>
            </div>
            <el-button type="primary" class="action-button">
              开始使用 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>
        
        <el-card class="feature-card" @click="$router.push('/knowledge')">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Search /></el-icon>
            </div>
            <div class="text-content">
              <h2>知识查询</h2>
              <p>基于自然语言的智能问答系统，快速获取所需知识</p>
            </div>
            <el-button type="primary" class="action-button">
              开始查询 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>
        
        <el-card class="feature-card" @click="$router.push('/graph')">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Share /></el-icon>
            </div>
            <div class="text-content">
              <h2>图谱可视化</h2>
              <p>直观展示知识实体关系，支持交互式探索与分析</p>
            </div>
            <el-button type="primary" class="action-button">
              查看图谱 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>

        <el-card class="feature-card" @click="$router.push('/searchChart')">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Histogram /></el-icon>
            </div>
            <div class="text-content">
              <h2>我的搜索</h2>
              <p>查看由搜索历史构建的图表</p>
            </div>
            <el-button type="primary" class="action-button">
              查看图表 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>

        <el-card class="feature-card" @click="$router.push('/manageMain')" v-if="isAdmin">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Avatar /></el-icon>
            </div>
            <div class="text-content">
              <h2>用户管理</h2>
              <p>知识平台管理员管理所有用户</p>
            </div>
            <el-button type="primary" class="action-button">
              查看用户 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>

        <el-card class="feature-card" @click="$router.push('/Abstract')">
          <div class="card-content">
            <div class="icon-circle">
              <el-icon size="40"><Promotion /></el-icon>
            </div>
            <div class="text-content">
              <h2>用户反馈</h2>
              <p>向知识管理员提出反馈信息，由他们来做问题处理</p>
            </div>
            <el-button type="primary" class="action-button">
              我要反馈 <el-icon><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>
      </div>

      <div class="stats-section">
        <div class="stats-grid">
          <div class="stat-card">
            <div class="stat-icon">
              <el-icon size="30"><Connection /></el-icon>
            </div>
            <div class="stat-content">
              <h3>{{ stats.entities }}</h3>
              <p>知识实体</p>
            </div>
          </div>
          <div class="stat-card">
            <div class="stat-icon">
              <el-icon size="30"><Share /></el-icon>
            </div>
            <div class="stat-content">
              <h3>{{ stats.relations }}</h3>
              <p>关系数量</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted ,computed} from 'vue'
import { Document, Search, Share, ArrowRight, Connection } from '@element-plus/icons-vue'
import axios from 'axios'
const isAdmin = computed(() => localStorage.getItem('isAdmin') === 'true')

const stats = ref({
  documents: 0,
  entities: 0,
  relations: 0
})

const loadStats = async () => {
  try {
    const response = await axios.get('/api/stats')
    if (response.data.code === 200) {
      const data = response.data.data
      stats.value = {
        documents: data.totalDocuments || 0,
        entities: data.totalNodes || 0,
        relations: data.totalRelationships || 0
      }
    }
  } catch (error) {
    console.error('Failed to load stats:', error)
  }
}

onMounted(() => {
  loadStats()
})
</script>

<style scoped>
html, body {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}
.home {
  width: 100vw;
  min-height: calc(100vh - 60px);
  background: #f5f7fa;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  margin: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

}

.welcome-section {
  width: 100vw;
  padding: 80px 20px;
  background: linear-gradient(135deg, #409EFF 0%, #36D1DC 100%);
  display: flex;
  justify-content: center;
  align-items: center;
}

.welcome-content {
  text-align: center;
  color: white;
  max-width: 800px;
}

.welcome-section h1 {
  font-size: 3em;
  margin-bottom: 20px;
  color: white;
  font-weight: 600;
}

.subtitle {
  font-size: 1.4em;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
}

.content-section {
  width: 100%;
  max-width: 1200px;
  margin: -40px auto 40px;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}

.feature-card {
  height: 100%;
  border: none;
  border-radius: 12px;
  transition: transform 0.3s ease;
  cursor: pointer;
}

.feature-card:hover {
  transform: translateY(-5px);
}

.card-content {
  padding: 30px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: white;
}

.icon-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(64, 158, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  color: #409EFF;
}

.text-content {
  flex-grow: 1;
  width: 100%;
  margin-bottom: 20px;
}

.text-content h2 {
  font-size: 1.5em;
  color: #2c3e50;
  margin-bottom: 15px;
  font-weight: 600;
}

.text-content p {
  color: #666;
  line-height: 1.6;
  margin: 0;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 1.1em;
}

.action-button .el-icon {
  margin-left: 4px;
}

.stats-section {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: #409EFF;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-content {
  flex: 1;
}

.stat-content h3 {
  font-size: 2em;
  color: #409EFF;
  margin: 0 0 5px;
  font-weight: 600;
}

.stat-content p {
  color: #666;
  margin: 0;
  font-size: 1em;
}

@media (max-width: 1200px) {
  .content-section {
    max-width: 900px;
  }
  
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .welcome-section {
    padding: 60px 20px;
  }
  
  .welcome-section h1 {
    font-size: 2.2em;
  }
  
  .subtitle {
    font-size: 1.2em;
  }
  
  .content-section {
    margin-top: -30px;
  }
  
  .features-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .card-content {
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .welcome-section h1 {
    font-size: 1.8em;
  }
  
  .subtitle {
    font-size: 1em;
  }
  
  .content-section {
    padding: 0 15px;
  }
}
</style> 